import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'messages_all.dart';

class DemoLocalizations {
  static Future<DemoLocalizations> load(Locale locale) {
    final String name =
        locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
    final String localName = Intl.canonicalizedLocale(name);
    return initializeMessages(localName).then((b) {
      Intl.defaultLocale = localName;
      return new DemoLocalizations();
    });
  }

  static DemoLocalizations of(BuildContext context) =>
      Localizations.of(context, DemoLocalizations);

  String get title => Intl.message(
        'Flutter App',
        name: 'title',
        desc: 'Title for the Demo application',
      );

  remainingEmailMessage(int howMany) => Intl.plural(
        howMany,
        zero: 'There are no emails left',
        one: 'There is $howMany email left',
        other: 'There are $howMany emails left',
        name: 'remainingEmailMessage',
        args: [howMany],
        desc: 'How many emails remain after archiving.',
        examples: const {'howMany': 42, 'userName': 'Yuangu'},
      );
}

class DemoLocalizationsDelegate
    extends LocalizationsDelegate<DemoLocalizations> {
  @override
  bool isSupported(Locale locale) => ['zh', 'en'].contains(locale.languageCode);

  @override
  Future<DemoLocalizations> load(Locale locale) =>
      DemoLocalizations.load(locale);

  @override
  bool shouldReload(LocalizationsDelegate<DemoLocalizations> old) => false;
}
